package org.fxcontainer.utils
{
	import mx.core.UIComponent;
	import mx.events.FlexEvent;
	
	import org.fxcontainer.commands.ControlAppearCommand;
	import org.fxcontainer.controls.IControl;
	
	/**
	 * The control register helper.
	 * @author Izzet_Mustafayev
	 */
	public final class ControlRegisterHelper
	{
		
		/**
		 * Control register helper method incapsulates <code>IControl</code> registering logic.<br/> 
		 * This is necessary because Flex does not support multi inheritence. 
		 * @param event the event
		 */
		static public function register(event:FlexEvent):void
		{	
			//announce controll appearence
			if (null != event){
				if (null != event.target && event.target is IControl){
					var control:IControl = IControl(event.target);
					//proceed some validation
					if (control.controlName() == null && UIComponent(control).id == null){
						throw Error("IControl implementation should have and \"id\" or \"controlname\" attributes set.");
					}
					//TODO: try to add your own control name
					new ControlAppearCommand(ControlAppearCommand.CTRL_APPEAR_CMD, control).dispatch();
				}
			}
		}
	}
}